﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Content;

namespace SimpleGameData.GameObjects.Particles
{
    public class EmitterData : GameObjectData
    {
        #region Fields

        // The amount of particles of this emitter
        private int particleCount;

        #endregion

        #region Min/Max Fields

        // min and max life time of the particles to be randomed between
        private float minLife;
        private float maxLife;

        // min and max velocity of the particles to be randomed between
        private float minVelocity;
        private float maxVelocity;

        #endregion

        #region Properties

        /// <summary>
        /// The amount of particles of this emitter
        /// </summary>
        public int ParticleCount
        {
            get { return particleCount; }
            set { particleCount = value; }
        }

        #endregion

        #region Min/Max Properties

        /// <summary>
        /// Min life time of the particles to be randomed between
        /// </summary>
        public float MinLife
        {
            get { return minLife; }
            set { minLife = value; }
        }

        /// <summary>
        /// Max life time of the particles to be randomed between
        /// </summary>
        public float MaxLife
        {
            get { return maxLife; }
            set { maxLife = value; }
        }

        /// <summary>
        /// Min velocity of the particles to be randomed between
        /// </summary>
        public float MinVelocity
        {
            get { return minVelocity; }
            set { minVelocity = value; }
        }
        
        /// <summary>
        /// Max velocity of the particles to be randomed between
        /// </summary>
        public float MaxVelocity
        {
            get { return maxVelocity; }
            set { maxVelocity = value; }
        }

        #endregion

        #region Constructor

        public EmitterData()
        {

        }

        #endregion
    }

    #region ContentTypeReader Class

    public class EmitterDataReader : ContentTypeReader<EmitterData>
    {
        protected override EmitterData Read(ContentReader input,
            EmitterData existingInstance)
        {
            EmitterData emitterData = existingInstance;

            if (emitterData == null)
            {
                emitterData = new EmitterData();
            }

            input.ReadRawObject<GameObjectData>(emitterData as GameObjectData);

            emitterData.ParticleCount = input.ReadInt32();
            emitterData.MinLife = input.ReadSingle();
            emitterData.MaxLife = input.ReadSingle();
            emitterData.MinVelocity = input.ReadSingle();
            emitterData.MaxVelocity = input.ReadSingle();

            return emitterData;
        }
    }
    #endregion
}
